package genetic.q3.functions;

import genetic.Function;
import genetic.TreeNode;

public class Divide extends SymbolicRegressionFunction{

	public Divide() {
		super(null);
	}

	public Divide(TreeNode[] kids) {
		super(kids);
	}

	@Override
	public Function createInstance(TreeNode[] kids) {
		return new Divide(kids);
	}

	@Override
	public TreeNode createRandomInstance(TreeNode[] kids) {
		return new Divide(kids);
	}

	@Override
	public int getNumKids() {
		return 2;
	}
	
	public double compute(double xVal){
		double val1 = ((Computable)kids[0]).compute(xVal);
		double val2 = ((Computable)kids[1]).compute(xVal);
		if (val2 == 0) return 1;
		else return val1/val2;
	}
	
	@Override
	public String getName() {
		return "/";
	}

}
